package server.phone.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import net.sf.json.JSONObject;
import server.phone.dao.BillAndPdtDAO;
import server.phone.dao.BillDAO;

import com.opensymphony.xwork2.ActionSupport;
import com.utopia84.model.Bill;
import com.utopia84.model.Billandpdt;

public class GetBillAndPdtServlet extends ActionSupport {
	private static final long serialVersionUID = -7811568044252827351L;
	private HttpServletRequest request;
	private HttpServletResponse response;
	
	public GetBillAndPdtServlet(){
		request = ServletActionContext.getRequest();
		response = ServletActionContext.getResponse();
	}
	
	 
	public void doGet() throws IOException, ClassNotFoundException, SQLException {

		Billandpdt bap=new Billandpdt();
		BillAndPdtDAO bapd=new BillAndPdtDAO();
		List<Billandpdt> baps = null;
		String billId = request.getParameter("billId");
		String salerecordId = request.getParameter("salerecordId");

		System.out.println("GetBillAndPdtServlet:"+"billId="+billId+",salerecordId="+salerecordId);
		
		JSONObject jObject = new JSONObject();
		JSONObject jData = new JSONObject();

		baps = bapd.GetBillAndPdt(billId,salerecordId);
		jData.put("Billandpdts", baps);
		jObject.put("ret", "success");
		jObject.put("data", jData);

		PrintWriter out = response.getWriter();
		System.out.println(jObject.toString());
		out.println(jObject);
		out.flush();
		out.close();

	}

}
